﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using zserialize;

public class MySerializeListener : CustomSerializeListener
{
	public bool isCustomSerializable(System.Type t)
	{
		if(t == typeof(TestCustomClass))
		{
			return true;
		}

		return false;
	}

    public void Write(System.IO.BinaryWriter binaryWriter, object obj, Dictionary<Object, short> objIndexMap, List<Object> objList, HashSet<System.Type> typeSet)
    {
    	if(obj is TestCustomClass)
    	{
    		TestCustomClass tcc = obj as TestCustomClass;
    		binaryWriter.Write((byte)1);
    		binaryWriter.Write(tcc.b);
    		binaryWriter.Write(tcc.ss);
    	}
    }

    public object Read(System.IO.BinaryReader binaryReader, Object[] objs)
    {
    	byte t = binaryReader.ReadByte();
    	if(t == 1)
    	{
    		TestCustomClass tcc = new TestCustomClass();
    		tcc.b = binaryReader.ReadInt32();
    		tcc.ss = binaryReader.ReadString();
    		return tcc;
    	}

    	return null;
    }
}